package com.toocms.jinjuhang.dialog.specification

import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import com.blankj.utilcode.util.LogUtils
import com.toocms.jinjuhang.data.goods.AttrValuesItemData
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand

class SpecificationAttrItemModel(
    val viewModel: SpecificationModel,
    val attrGroupItemViewModel: SpecificationAttrGroupItemModel,
    val item: ObservableField<AttrValuesItemData>,
    val isSelectedObservableBoolean: ObservableBoolean = ObservableBoolean(
        false
    )
) {

    val itemClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
        //修改记录的规格ID
        val itemIndex = viewModel.attrItems.indexOf(attrGroupItemViewModel)
        LogUtils.e(viewModel.selectedAttrIds?.size, viewModel.selectedAttrNames?.size)
        viewModel.selectedAttrIds!![itemIndex] = item.get()?.goods_attr_id ?: null
        viewModel.selectedAttrNames!![itemIndex] = item.get()?.attr_value ?: null
//        LogUtils.e(viewModel.selectedAttrIds,viewModel.selectedAttrNames)
        //获取库存和价格
        viewModel.getSku()
        //修改选择的规格
        attrGroupItemViewModel.items.forEach {
            it.isSelectedObservableBoolean.set(it == this@SpecificationAttrItemModel)
        }
    })

}